<?php require_once '../global.php';

function king_def(){
	global $king;
	$king->access('keywords');

$_cmd=array(
		'delete'=>$king->lang->get('system/common/del'),
	);
	$manage ="'<a target=\"_blank\" href=\"/tag/'+(K[3])+'".$sd."\">'+$.kc_icon('h7','".$king->lang->get('system/common/brow')."')+'</a>'";
	$manage.="+'<a href=\"javascript:;\" class=\"k_ajax\" rel=\"{CMD:\'delete\',list:'+K[0]+'}\">'+\$.kc_icon('l5','".addslashes($king->lang->get('system/common/del'))."')+'</a>'";
	$manage.="+'<a href=\"../soso/search.php?ktitle='+(K[1])+'\">'+\$.kc_icon('h6','".addslashes('添加知道')."')+'</a>'";
	$manage.="+\$.kc_updown(K[0])";

	$_js=array(
		"\$.kc_list(K[0],K[1],'manage_sj.php?action=view&mid='+K[0])",
		$manage,
		"'<i>'+ishow('manage_sj.php',K[0],K[2])+'</i>'",//显示
		"K[3]",
		"K[4]",
	);
	$s=$king->openList($_cmd,'',$_js,$king->db->pagelist('manage_sj.php?pid=PID&rn=RN',$king->db->getRows_number('metas','mid!=0')));




	$_sql="select mid,name,slug,nshow,count from metas order by nshow asc,mid desc";
	if(!$res=$king->db->getRows($_sql,1)) $res=array();


	$s.="function ishow(url,id,is){var I1,ico;is?ico='n1':ico='n2';";
	$s.="I1='<a id=\"nshow_'+id+'\" class=\"k_ajax\" rel=\"{CMD:\'show\',value:'+ (1-is) +',ID:\'nshow_'+id+'\',list:'+id+',IS:2}\" >'+$.kc_icon(ico,(is?'".$king->lang->get('keywords/list/unshow')."':'".$king->lang->get('keywords/list/show')."'))+'</a>';return I1;};";
	$s.="ll('".$king->lang->get('keywords/list/title')."',
	    'manage',
		'".$king->lang->get('keywords/list/show')."',
	    '".$king->lang->get('keywords/list/ktag')."',
	    '".$king->lang->get('keywords/list/date')."',1);";


	foreach($res as $rs){
		$s.="ll({$rs['mid']},
		    '".addslashes(htmlspecialchars($rs['name']))."',
		    ".$rs['nshow'].",
		    '".$rs['slug']."',
		    '".$rs['count']."',0);";
	}




	$s.=$king->closeList();

	list($left,$right)=inc_menu();

			
	$king->skin->output($king->lang->get('keywords/title/center'),$left, $bs,$s);

}


/**
菜单调用
*/
function inc_menu(){
	global $king;
	$left=array(
		'0'=>array(
			'href'=>'manage.php',
			'ico'=>'p7',
			'title'=>$king->lang->get('keywords/list/title'),
			),
		'3'=>array(
			'href'=>'manage_sj.php',
			'ico'=>'p7',
			'title'=>'商家',
			),
		'1'=>array(
			'href'=>'manage_tag.php',
			'ico'=>'p7',
			'title'=>$king->lang->get('keywords/list/ktag'),
			),
		'fc'=>array(
			'href'=>'javascript:;',
			'ico'=>'c2',
			'title'=>'添加分词',
			'rel'=>"{CMD:'fc',METHOD:'GET',URL:'./index.php'}",
			'class'=>"k_ajax",
		),
		'edt'=>array(
			'href'=>'javascript:;',
			'ico'=>'c2',
			'title'=>'添加关键词',
			'rel'=>"{CMD:'edt',METHOD:'GET',URL:'./index.php'}",
			'class'=>"k_ajax",
		),
	);
	

	return array($left,array());
}



//删除留言
function king_ajax_delete(){
	global $king;
	$king->access('keywords_delete');
	$list=kc_getlist();
	$king->db->query("delete from metas where mid in ($list)");
	kc_ajax('OK',"<p class=\"k_ok\">".$king->lang->get('system/ok/delete')."</p>",1);
}


//排序
function king_ajax_updown(){
	global $king;
	$king->access('key_updown');

	$mid=kc_get('mid',2,1);
	$king->db->updown('metas',$mid);
}

//显示隐藏
function king_ajax_show(){
	global $king;
	$king->access('keywords_edt');
	$mid=kc_get('list',2,1);
	$value=kc_get('value',2,1);
	$king->db->query("update metas set nshow=$value where mid=$mid;");
	$value ? $ico='n1':$ico='n2';
	kc_ajax('',
		kc_icon($ico,($value?$king->lang->get('keywords/list/unshow'):$king->lang->get('keywords/list/show'))),
		0,
		"$('#nshow_{$mid}').attr('rel','{CMD:\'show\',value:".(1-$value).",ID:\'nshow_{$mid}\',list:\'$mid\',IS:2}')");
}




function king_view(){
	global $king;
	$king->access('keywords');
	
	$mid=kc_get('mid',2);
	$sql="*";

	if(!$res=$king->db->getRows("select $sql from metas where mid=$mid"))
		$res=array();

	if(empty($mid)){
		kc_error($king->lang->get('system/error/param'));
	}else{
		if(!$rs=$king->db->getRows_one("select $sql from metas where mid=$mid order by mid asc"))
			kc_error($king->lang->get('system/error/notrecord'));

		foreach ($rs as &$r) {
			$r=htmlspecialchars($r);
		}
		$rs['kcontent']=nl2br($rs['kcontent']);

		$s=$king->openForm($king->lang->get('keywords/name'),'','keywords_edt');
		$s.=$king->htmForm($king->lang->get('keywords/label/title'),$rs['ktitle']);
		$s.=$king->htmForm($king->lang->get('keywords/label/name'),$rs['ktag']);
		$s.=$king->htmForm($king->lang->get('keywords/label/content'),$rs['kcontent']);
		$s.=$king->htmForm($king->lang->get('keywords/label/date'),kc_formatdate($rs['ndate']));

		$but='<input type="button" onclick="javascript:history.back(-1)" value="'.$king->lang->get('system/common/back').'[B]" class="big" accesskey="b"/>';

		$s.=$king->htmForm(null,$but);
		$s.=$king->closeForm('none');
	}




	list($left,$right)=inc_menu();
	$king->skin->output($king->lang->get('keywords/title/center'),$left,$right,$s);

}
?>